package com.yanqu.road.dao.impl.activity.suoyao;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.suoyao.config.SuoYaoViewBookConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SuoYaoViewBookConfigDaoImpl extends TempDao {
    private static String getSuoYaoViewBookConfigSql = "select * from `t_s_activity_suoyao_view_book` where `activityId`=?";
    public Map<Integer,SuoYaoViewBookConfig> getSuoYaoViewBookConfigMap(int activityId) {
        Map<Integer,SuoYaoViewBookConfig> map = new HashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSuoYaoViewBookConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SuoYaoViewBookConfig suoYaoViewBookConfig = new SuoYaoViewBookConfig();
                suoYaoViewBookConfig.setActivityId(rs.getInt("activityId"));
                suoYaoViewBookConfig.setBookId(rs.getInt("bookId"));
                suoYaoViewBookConfig.setLayer(rs.getInt("layer"));
                suoYaoViewBookConfig.setName(rs.getString("name"));
                suoYaoViewBookConfig.setDesc(rs.getString("desc"));
                suoYaoViewBookConfig.setViewReward(rs.getString("viewReward"));
                map.put(suoYaoViewBookConfig.getBookId(),suoYaoViewBookConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
